home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #33 (Jun 88) / icon source / StdMenu.pas < prev    next >
Pascal/Delphi Source File  |  1988-03-28  |  3KB  |  146 lines

  1. {
  2. |    StdMenu provides standard menu objects.
  3. }
  4. unit StdMenu;
  5.  
  6. interface
  7.  
  8. uses MacIntf, StdPoll;
  9.  
  10. const
  11.     { Standard File menu item numbers }
  12.     NewItem = 1;
  13.     OpenItem = 2;
  14.     CloseItem = 3;
  15.     { ------ }
  16.     SaveItem = 5;
  17.     SaveAsItem = 6;
  18.     RevertItem = 7;
  19.     { ------ }
  20.     PageSetupItem = 9;
  21.     PrintItem = 10;
  22.     { ------ }
  23.     QuitItem = 12;
  24.  
  25. type    
  26.     {    
  27.     |    MenuHdlr is the base object for all menus.
  28.     |    The Create method installs the menu at the end of
  29.     |    the menu bar.  The Choose method should be overridden
  30.     |    with code to perform a menu choice.
  31.     }
  32.     MenuHdlr = object
  33.         TheMenu : MenuHandle;
  34.         procedure Create (RsrcID : Integer);
  35.         procedure Choose (Choice : Integer);
  36.     end;
  37.     
  38.     {
  39.     |    AppleMenuHdlr provides all the functionallity of
  40.     |    a standard Apple menu.  It must be Setup with an 
  41.     |    alert id for the About… message before Create is
  42.     |    called.
  43.     }
  44.     AppleMenuHdlr = object (MenuHdlr)
  45.         AboutID : Integer;
  46.         procedure Create (RsrcID : Integer); override;
  47.         procedure Choose (Choice : Integer); override;
  48.         procedure Setup (AlertID : Integer);
  49.     end;
  50.  
  51.     {
  52.     |    StdFileMenuHdlr is a minimal File menu.  The Choose
  53.     |    method can Close DA's and Quit.
  54.     }
  55.     StdFileMenuHdlr = object (MenuHdlr)
  56.         procedure Choose (Choice : Integer); override;
  57.     end;
  58.     
  59.     {
  60.     |    StdEditMenuHdlr is a minimal Edit menu.  The Choose
  61.     |    method supports DA editing.
  62.     }
  63.     StdEditMenuHdlr = object (MenuHdlr)
  64.         procedure Choose (Choice : Integer); override;
  65.     end;
  66.     
  67. { ----------------------------------------------------------------------- }
  68. implementation 
  69.  
  70. {
  71. |    Generic Menu Handler
  72. }
  73. procedure MenuHdlr.Create (RsrcID : Integer);
  74. begin
  75.     { Read in a standard menu resource.
  76.     | Remember: Object variables are Handles! 'Self' is set only
  77.     | as you enter the method, so HLock it if you call any
  78.     | potential heap-scramblers! }
  79.     HLock(Handle(Self));
  80.     TheMenu := GetMenu (RsrcID);
  81.     InsertMenu (TheMenu, 0);
  82.     HUnlock(Handle(Self)) end;
  83.  
  84. procedure MenuHdlr.Choose (Choice : Integer);
  85. begin end;
  86.  
  87. {
  88. |    Apple Menu Handler
  89. }
  90. procedure AppleMenuHdlr.Create (RsrcID : Integer);
  91. begin
  92.     { Read in the Apple menu stub, and add DA's }
  93.     HLock(Handle(Self));
  94.     TheMenu := GetMenu (RsrcID);
  95.     AddResMenu (TheMenu, 'DRVR');
  96.     InsertMenu (TheMenu, 0);
  97.     HUnlock(Handle(Self)) end;
  98.     
  99. procedure AppleMenuHdlr.Choose (Choice : Integer);
  100. var
  101.     AccName : Str255;
  102.     AccNumber : integer;
  103. begin
  104.     { Post alert or open DA }
  105.     if Choice = 1
  106.     then AccNumber := Alert (AboutID, NIL)
  107.     else begin
  108.         GetItem (TheMenu, Choice, AccName);
  109.         AccNumber := OpenDeskAcc (AccName) end end;
  110.         
  111. procedure AppleMenuHdlr.Setup (AlertID : Integer);
  112. begin
  113.     AboutID := AlertID end;
  114.  
  115. {
  116. |    Standard File Menu
  117. }
  118. procedure StdFileMenuHdlr.Choose (Choice : Integer);
  119. var
  120.     FrontWP : windowPeek;
  121. begin
  122.     case Choice of
  123.     NewItem : ;
  124.     OpenItem : ;
  125.     CloseItem : begin { If frontmost window is DA, close it. }
  126.         FrontWP := windowPeek(frontWindow);
  127.         if FrontWP^.windowKind < 0
  128.         then CloseDeskAcc(FrontWP^.windowKind) end;
  129.     SaveItem : ;
  130.     SaveAsItem : ;
  131.     RevertItem : ;
  132.     PageSetupItem : ;
  133.     PrintItem : ;
  134.     QuitItem : Done := true;
  135.     otherwise  { nothing } end end;
  136.  
  137. {
  138. |    Standard Edit menu
  139. }
  140. procedure StdEditMenuHdlr.Choose (Choice : Integer);
  141. var
  142.     Trash : Boolean;
  143. begin
  144.     Trash := SystemEdit (Choice-1) end;
  145.  
  146. end. { of StdMenu unit }